package com.mobilebsc.httpclient.callback;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.mobilebsc.datatype.WeakSignal;

public class WeakSignalReferencedByX_HttpResponseHandler extends
		WeakSignalHttpResponseHandler {

	private static final String TAG = "WeakSignalReferencedByX_HttpResponseHandler";

	public WeakSignalReferencedByX_HttpResponseHandler(
			IAsyncTaskCompleteListener<List<WeakSignal>> callback) {
		super(callback);
	}

	@Override
	public void onSuccess(JSONArray referencedWeakSignals) {

		Log.i(TAG, "onSuccess0 = JSON length " + referencedWeakSignals.length()
				+ ", JSON string " + referencedWeakSignals.toString());

		weakSignalsList = new ArrayList<WeakSignal>();
		JSONObject weakSignalJSON = new JSONObject();

		if (referencedWeakSignals.length() == 0) {
			weakSignalsList.add(new WeakSignal());
		} else {
			for (int i = 0; i < referencedWeakSignals.length(); i++) {
				try {
					weakSignalJSON = referencedWeakSignals.getJSONObject(i)
							.optJSONObject("weaksignal");

					WeakSignal weakSignal = new WeakSignal(weakSignalJSON);

					weakSignalsList.add(weakSignal);
				} catch (JSONException e) {
					Log.e(TAG, "onSuccess = " + e.toString());
				}
			}
		}
	}
}